#include "storevariable.h"
//
storeVariable::storeVariable(Variable *V,VariableList *L,VariableStack *S,QUndoCommand *parent) 
	: QUndoCommand(parent)
{
	setText("Var stored");
	Name=V->Name;
	Val=V->Data;
	Expr=V->Expression;
	List=L;
	Stack=S;
	
	bool exist;
	PrevVal=List->getValFromName(Name,exist);
	if(exist) PrevExpr=List->getExprFromName(Name,exist);
	else{
		PrevVal=0;
		PrevExpr="";
	}
	
}

void storeVariable::undo(){
	if(PrevExpr!=""){
		Variable *V;
		V=new Variable(Name,PrevVal,PrevExpr);
		List->put(V);
		Stack->put(V);
		delete V;
	}
	else{
		List->remove(Name);
		Stack->pop();
	}
}

void storeVariable::redo(){
	Variable *V;
	V=new Variable(Name,Val,Expr);
	List->put(V);
	Stack->put(V);
	delete V;
}

//
